<template>
  <div class="my_house">
    <head-top head-title="我的房" goBack="true"></head-top>
    <div>
      <div class="house_list border-bottom-last" v-for="(item,index) in lists" @click="toResult(item.id)" :key="index">
        <div class="house_img">
          <img src="./images/Hdefault.png" alt="">
        </div>
        <div class="house_msg">
          <p>{{item.title}}</p>
          <p>{{item.fang}}</p>
          <p>业主</p>
        </div>
        <div class="go_icon">
          <img src="../home/images/fanhui1@2x.png" alt="">
        </div>
      </div>
    </div>
    <div class="home_addBtn">
      <button @click="toHouseConfirm()">
        <span>+添加房屋</span>
      </button>
    </div>
  </div>
</template>
<style lang="scss">
  /*@import "../../common/sass/index.scss";*/

  .my_house {
    width: 100%;
    padding-top: 40px;
    .house_list {
      flex-direction: row;
      display: flex;
      align-items: center;
      .house_img {
        width: 20%;
        img {
          width: 100%;
          opacity: 0.7;
        }
      }
      .house_msg {
        width: 75%;
        p:first-child {
          font-size: 15px;
          color: #000;
        }
        p {
          font-size: 13px;
          color: #6e6e6e;
          line-height: 24px;
        }
      }
      .go_icon {
        width: 5%;
        img {
          width: 10px;
        }
      }
    }
    .home_addBtn {
      width: 100%;
      text-align: center;
      margin-top: 20px;
      padding-bottom: 20px;
      button {
        width: 90%;
        background: #0078de;
        outline: none;
        span {
          line-height: 44px;
          font-size: 15px;
          color: #fff;
        }
      }
    }
  }
</style>
<script>
  import headTop from '../header/Header.vue'
  import {
          loadPhoneName
          } from '../../common/js/cache.js'
  import {Toast} from 'mint-ui'
  import {getDatas} from '../../api/my.js'

  export default {
    name: 'MyHouse',
    data () {
      return {
        lists: []
      }
    },
    components: {
      headTop
    },
    created () {
      this._getDatas()
    },
    methods: {
      _getDatas () {
        // const url = commonUrl.apihost + 'index.php/home/house_Auth/getMyHouse?openid=oHVoI1YSCHpddlq7bEXa62gcdbTA'
        getDatas().then(res => {
          if (res.code === 200) {
            this.lists = res.data
          }
        })
      },
      toHouseConfirm () {
        if ((loadPhoneName().phone === '0' || loadPhoneName().phone === '') || loadPhoneName().name === '') {
          this.$router.push('/EditData1')
          Toast({
            message: '请先编辑资料',
            position: 'middle',
            duration: 1500
          })
        } else {
          this.$router.push('/my/HouseConfirm')
        }
      },
      toResult (id) {
        this.$router.push('/my/Result/' + id)
      }
    }
  }
</script>
